﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace SachOnlineLibrary.DAL
{
    internal class LoaiDAL
    {
        KetNoiDB ketnoidb;

        internal LoaiDAL()
        {
            ketnoidb = new KetNoiDB();
        }

        internal DataRow LietKeLoaiTheoMaLoai(int maloai)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select * from Loai where Maloai = @maloai";
            cmd.Parameters.Add("@maloai", SqlDbType.Int).Value = maloai;
            DataTable dt = new DataTable();
            try
            {
                dt = ketnoidb.ExecuteQuery(cmd);
                DataRow dr = dt.NewRow();
                dr = dt.Rows[0];
                return dr;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return null;
            }
        }

        internal DataTable LietKeTatCaLoai()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select * from Loai";
            DataTable dt = new DataTable();
            try
            {
                dt = ketnoidb.ExecuteQuery(cmd);
                return dt;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return null;
            }
        }
    }
}
